What is is-absolute?
The is-absolute npm package is a utility that helps determine if a given file path is an absolute path. This can be particularly useful in file system operations where the distinction between absolute and relative paths is important.
What are is-absolute's main functionalities?
Check if a path is absolute
This feature allows you to check if a given path is absolute. An absolute path is one that starts from the root directory, as opposed to a relative path which is relative to the current working directory.
const isAbsolute = require('is-absolute');
console.log(isAbsolute('/home/user')); // true
console.log(isAbsolute('home/user')); // false
Other packages similar to is-absolute
path-is-absolute
The path-is-absolute package provides similar functionality to is-absolute by determining if a given path is absolute. It is a lightweight package and can be used as a drop-in replacement for is-absolute.
path
The path module is a core Node.js module that provides utilities for working with file and directory paths. It includes a method called path.isAbsolute() which can be used to check if a path is absolute. This module offers a broader range of path-related utilities compared to is-absolute.
is-absolute
Returns true if a file path is absolute. Does not rely on the path module and can be used as a polyfill for node.js native path.isAbolute
.
Install
Install with npm:
$ npm install --save is-absolute
Originally based on the isAbsolute
utility method in express.
Usage
var isAbsolute = require('is-absolute');
isAbsolute('a/b/c.js');
isAbsolute('/a/b/c.js');
Explicitly test windows paths
isAbsolute.posix('/foo/bar');
isAbsolute.posix('/user/docs/Letter.txt');
isAbsolute.posix('foo/bar');
Explicitly test windows paths
var isAbsolute = require('is-absolute');
isAbsolute.win32('c:\\');
isAbsolute.win32('//C://user\\docs\\Letter.txt');
isAbsolute.win32('\\\\unc\\share');
isAbsolute.win32('\\\\unc\\share\\foo');
isAbsolute.win32('\\\\unc\\share\\foo\\');
isAbsolute.win32('\\\\unc\\share\\foo\\bar');
isAbsolute.win32('\\\\unc\\share\\foo\\bar\\');
isAbsolute.win32('\\\\unc\\share\\foo\\bar\\baz');
isAbsolute.win32('a:foo/a/b/c/d');
isAbsolute.win32(':\\');
isAbsolute.win32('foo\\bar\\baz');
isAbsolute.win32('foo\\bar\\baz\\');
About
Related projects
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Contributors
Building docs
(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)
To generate the readme, run the following command:
$ npm install -g verbose/verb
Running tests
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
$ npm install && npm test
Author
Jon Schlinkert
License
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
This file was generated by verb-generate-readme, v0.6.0, on July 13, 2017.